﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Pretext.Formatters {

	/// <summary>
	/// A formatter for turning strings into C style formatted strings.
	/// </summary>
    public class CStringFormatter : IFormatter {

        public bool EscapeLineFeeds { get; set; }
        public bool EscapeQuotes { get; set; }
        public bool EscapeTabs { get; set; }

        public CStringFormatter() {
            EscapeLineFeeds = true;
            EscapeQuotes = true;
            EscapeTabs = true;
        }

		/// <summary>
		/// Formats a string into a C style formatted string.
		/// </summary>
		/// <param name="s"></param>
		/// <returns>Returns a new string contianing a C style formatted version of the specified string.</returns>
        public string Format(string s) {
            if (EscapeLineFeeds) {
                s = s.Replace("\n", @"\n");
                s = s.Replace("\r", @"\r");
            }
            if (EscapeQuotes)
                s = s.Replace("\"", "\\\"");
    
            if (EscapeTabs)
                s = s.Replace("\t", @"\t");

            return s;
        }
        
    }

}